<?php

class PageDao{
	
	public function getPages(){
		$result = DbUtils::execute("SELECT * FROM `page` LIMIT 0 , 30");
		
		$pages = array();
		while($row = mysql_fetch_array($result)){
			$page = new Page();
			$page->construct($row);
			array_push($pages, $page);
		}
		
		return $pages;
	}		
	
	
	public function addPage($page){		
		$name = $page->name;
		$slug = $page->slug;
		$templateId = $page->templateId;

		DbUtils::execute("INSERT INTO `page` (`id`, `name`, `slug`, `templateId`) VALUES ('', '".$name."', '".$slug."','".$templateId."')");
	}
	
	public function getPage($pageId){
		$result = DbUtils::execute("SELECT * FROM `page` WHERE `id`=".$pageId);
		$page=null;
		while($row = mysql_fetch_array($result)){
			$page = new Page();
			$page->construct($row);
		}
		return $page;		
	}	
}

class Page{
	public $id;
	public $name;
	public $templateId;
	public $slug;
		
	public function construct($row){
		$this->id = $row["id"];
		$this->name = $row["name"];
		$this->templateId = $row["templateId"];
		$this->slug = $row["slug"];
	}
}

?>
